﻿
using Xacml.Core.Interfaces;
using System.Collections;

namespace Xacml.Core.Runtime
{
  public class PolicyCombiningAlgorithmDenyOverrides : IPolicyCombiningAlgorithm
  {
    public Decision Evaluate(EvaluationContext context, IMatchEvaluableCollection policies)
    {
      bool flag = false;
      foreach (IMatchEvaluable matchEvaluable in (CollectionBase) policies)
      {
        switch (matchEvaluable.Evaluate(context))
        {
          case Decision.Deny:
            context.ProcessingError = false;
            context.IsMissingAttribute = false;
            return Decision.Deny;
          case Decision.Permit:
            flag = true;
            continue;
          case Decision.Indeterminate:
            context.ProcessingError = false;
            context.IsMissingAttribute = false;
            return Decision.Deny;
          default:
            continue;
        }
      }
      if (!flag)
        return Decision.NotApplicable;
      context.ProcessingError = false;
      context.IsMissingAttribute = false;
      return Decision.Permit;
    }
  }
}
